<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script type="text/javascript" src="../javascript/jquery.min.js"></script>


</head>

<div class="layui-form-item" style="margin-top: 15px;">
    <label class="layui-form-label" style="width: 50px;">周次：</label>
    <div class="layui-input-inline" style="width: 50px;">
        <input type="text" id="week" name="week" lay-verify="num" value="1" placeholder="请输入" autocomplete="off"
            class="layui-input">
    </div>
    <label class="layui-form-label" style="width: 50px;">星期：</label>

    <div class="layui-input-inline layui-form layui-form-pane" style="width: 100px;">
        <select name="modules" id="day" lay-verify="required" lay-search="">
            <option value="">选择星期</option>
            <option value="星期一">星期一</option>
            <option value="星期二">星期二</option>
            <option value="星期三">星期三</option>
            <option value="星期四">星期四</option>
            <option value="星期五">星期五</option>
        </select>
    </div>

    <label class="layui-form-label" style="width: 60px;">教室名：</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="text" id="roomName" name="roomName" lay-verify="required" placeholder="模糊搜索" autocomplete="off"
            class="layui-input">
    </div>
    <a class="layui-btn layui-btn" id="find" lay-event="addTeaching" style="margin-left: 50px;">查询空教室</a>

</div>



<table class="layui-hide" id="demo" name="user" lay-data="{height: 'full-200', cellMinWidth: 80, page: true, limit:10}"
    lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" id ="adjust" lay-event="adjust">调整</a>
  </script>
<script>


</script>
<script>
    var table;
    var courseTableId;
    $(document).ready(function () {
        courseTableId = window.location.href.split("=")[1];
        var patrn = /^\+?[1-9][0-9]*$/;
        $("#find").click(function () {
            var value = $("#week").val();
            if ($("#week").val() == "" || $("#week").val() == null) {
                layer.msg("请输入周次");
            } else if (value = null || value.length == 0 || patrn.exec(value) == null || value > 20 || value < 1) {
                layer.msg("周次只能为1-20非空数字");
                $("#week").val("");
            } else {
                console.log("1111111")
                reload();
            }
        });

    });

    //重新加载table
    function reload() {
        table.reload('demo', {
            url: "http://127.0.0.1:8088/classroom/findByWeek?week=" + $("#week").val()
                + "&roomName=" + $("#roomName").val()
                + "&day=" + $("#day  option:selected").val()
        })
    }

    layui.use(['table', 'layedit', 'laydate'], function () {
        var layer = layui.layer;
        table = layui.table //表格
        table.render({
            elem: '#demo'
            , url: 'http://127.0.0.1:8088/classroom/findByWeek?week=1' //数据接口
            , request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.status, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
            , title: '用户表'
            , size: "sm"
            , page: true //开启分页
            , cols: [[ //表头
                { type: 'checkbox', fixed: 'left' }
                , { field: 'week', title: '周次', sort: true, fixed: 'left', align: "center" }
                , { field: 'classroomName', title: '教室名字', align: "center" }
                , { field: 'day', title: '星期', sort: true, align: "center" }
                , { field: 'number', title: '节数', sort: true, align: "center" }
                , { fixed: 'right', align: 'center', toolbar: '#barDemo' }
            ]]
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'adjust') {
                //adjust(data)
                var day = data.day;
                var week = data.week;
                var number = data.number;
                var classroomId = data.classroomId;
                var classroomName = data.classroomName;
                console.log(day + " " + week + " " + number + " " + classroomId + " " + classroomName)
                console.log(courseTableId)
                var url = "http://127.0.0.1:8088/coursetable/adjust?day=" + day
                    + "&week=" + week + "&number=" + number + "&classroomId=" + classroomId + "&classroomName=" + classroomName
                    + "&courseTableId=" + courseTableId;
                console.log(url)
                $.get(url, function (data, status) {
                    var ret = JSON.parse(JSON.stringify(data));
                    if (ret.status == 1) {
                        layer.alert(ret.msg);
                    } else {
                        console.log(ret.msg)
                        layer.alert(ret.msg);
                        window.parent.location.reload();//刷新父页面
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭当前iframe页面
                        parent.location.reload();//刷新父页面
                    }
                });
            }
        });
    });

    function adjust(data) {

    }
</script>

<body>
</body>

</html>